package com.by.interceptor.config;

import com.by.autoconfig.LoginInteceptorProperties;
import com.by.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


public class LoginInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    LoginInteceptorProperties properties;

    @Autowired
    LoginInterceptor loginInterceptor;

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)//注入登录拦截器
                .addPathPatterns(properties.getPathPatterns())  //指定拦截路径 拦截所有的请求
                .excludePathPatterns(properties.getExcludePathPatterns());//  白名单  不拦截的请求
    }
}
